<?php
/*
Copyright 2008, Nathalia


Author:
Nathalia Sautchuk Patrício          (nathalia.sautchuk@gmail.com)

*/
Prado::using('System.Security.TDbUserManager');

class User extends TDbUser
{

    const ROLE_AUTOR         = 0;
	const ROLE_AVALIADOR     = 1;
	const ROLE_CP            = 2;
	const ROLE_ADMINISTRADOR = 3;

	public function createUser($username)
    {
        // use UserRecord Active Record to look for the specified username
        $userRecord=UserRecord::finder()->findByLogin($username);
        if($userRecord instanceof UserRecord) // if found
        {
            $user          = new User($this->Manager);
            $user->Name    = $userRecord->UsuarioID;  
            $user->Roles   = ($userRecord->Papel); // set role
            $user->IsGuest = false;   // the user is not a guest
            return $user;
        }
        else
            return null;
    }

    public function validateUser($username,$password)
    {
        return UserRecord::finder()->findBy_Login_AND_Senha($username,$password)!==null;
    }

    public function getIsAdmin()
    {
        if($this->Roles[0] == User::ROLE_ADMINISTRADOR) return true;
        else return false;
    }

    public function getIsAvaliador()
    {
        if($this->Roles[0] == User::ROLE_AVALIADOR) return true;
        else return false;
    }
    
    public function getIsAutor()
    {
        if($this->Roles[0] == User::ROLE_AUTOR) return true;
        else return false;
    }
    
    public function getIsCP()
    {
        if($this->Roles[0] == User::ROLE_CP) return true;
        else return false;
    }

    public function getUser()
    {
        
    }
}

?>
